﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace xiaolanshu
{
    public partial class 护肤_反馈 : Form
    {
        public SqlConnection conn;
        public 护肤_反馈()
        {
            InitializeComponent();
            //string cstr = @"server=.\SqlExpress;database=小兰书;integrated security=SSPI";
            //conn = new SqlConnection(cstr);
            conn = SQLTools.conn;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 护肤_反馈_Load(object sender, EventArgs e)
        {
            string sql = "select 商品名称 from 护肤";
            SqlCommand cmd=new SqlCommand(sql, conn);
            conn.Open();
            SqlDataReader rd=cmd.ExecuteReader();
            while(rd.Read())
            {
                comboBox1.Items.Add(rd[0]);
            }
            rd.Close();
            conn.Close();
            comboBox2.Items.Add("干皮");
            comboBox2.Items.Add( "油皮");
            comboBox2.Items.Add( "混合皮");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*int a = uiTrackBar1.Value;
            int b = uiTrackBar2.Value;
            int c= uiTrackBar3.Value;
            int d= uiTrackBar4.Value;
            //String sql = @"insert into 护肤反馈 values('''+comboBox1.Text+''','''+comboBox2.Text+''',uiTrackBar1.Value,uiTrackBar2.Value,uiTrackBar3.Value,uiTrackBar4.Value)";
            String sql = @"insert into 护肤反馈 values('''+comboBox1.Text+''','''+comboBox2.Text+''',a,b,c,d)";
            SqlCommand cmd= new SqlCommand(sql, conn);*/
            String sql = @"insert into 护肤反馈 values(@name,@skin,@total,@white,@wet,@absorb)";
            SqlCommand cmd=new SqlCommand(sql, conn);
            SqlParameter _name=new SqlParameter("@name",SqlDbType.VarChar,50);
            SqlParameter _skin = new SqlParameter("@skin", SqlDbType.VarChar, 50);
            SqlParameter _total = new SqlParameter("@total", SqlDbType.Int);
            SqlParameter _white = new SqlParameter("@white", SqlDbType.Int);
            SqlParameter _wet = new SqlParameter("@wet", SqlDbType.Int);
            SqlParameter _absorb = new SqlParameter("@absorb", SqlDbType.Int);
            cmd.Parameters.Add(_name);
            cmd.Parameters.Add(_skin);
            cmd.Parameters.Add(_total);
            cmd.Parameters.Add(_white);
            cmd.Parameters.Add(_wet);
            cmd.Parameters.Add(_absorb);
            _name.Value = comboBox1.Text;
            _skin.Value = comboBox2.Text;
            _total.Value = uiTrackBar1.Value;
            _white.Value = uiTrackBar2.Value;
            _wet.Value = uiTrackBar3.Value;
            _absorb.Value = uiTrackBar4.Value;
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("插入一条评价！", "成功");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "失败");
            }
            finally
            {
                conn.Close();
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.comboBox1.Text ="";
            this.comboBox2.Text = "";
            this.uiTrackBar1.Value = 0;
            this.uiTrackBar2.Value = 0;
            this.uiTrackBar3.Value = 0;
            this.uiTrackBar4.Value = 0;

        }
    }
}
